package com.ruoyi.material.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.material.domain.MaterialOperate;
import com.ruoyi.material.service.IMaterialOperateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 操作记录模块Controller
 * 
 * @author ruoyi
 * @date 2025-08-23
 */
@RestController
@RequestMapping("/material/operate")
public class MaterialOperateController extends BaseController
{
    @Autowired
    private IMaterialOperateService materialOperateService;

    /**
     * 查询操作记录模块列表
     */
    @PreAuthorize("@ss.hasPermi('material:operate:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialOperate materialOperate)
    {
        startPage();
        List<MaterialOperate> list = materialOperateService.selectMaterialOperateList(materialOperate);
        return getDataTable(list);
    }

    /**
     * 导出操作记录模块列表
     */
    @PreAuthorize("@ss.hasPermi('material:operate:export')")
    @Log(title = "操作记录模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialOperate materialOperate)
    {
        List<MaterialOperate> list = materialOperateService.selectMaterialOperateList(materialOperate);
        ExcelUtil<MaterialOperate> util = new ExcelUtil<MaterialOperate>(MaterialOperate.class);
        util.exportExcel(response, list, "操作记录模块数据");
    }

    /**
     * 获取操作记录模块详细信息
     */
    @PreAuthorize("@ss.hasPermi('material:operate:query')")
    @GetMapping(value = "/{operateId}")
    public AjaxResult getInfo(@PathVariable("operateId") Long operateId)
    {
        return success(materialOperateService.selectMaterialOperateByOperateId(operateId));
    }

    /**
     * 新增操作记录模块
     */
    @PreAuthorize("@ss.hasPermi('material:operate:add')")
    @Log(title = "操作记录模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialOperate materialOperate)
    {
        return toAjax(materialOperateService.insertMaterialOperate(materialOperate));
    }

    /**
     * 修改操作记录模块
     */
    @PreAuthorize("@ss.hasPermi('material:operate:edit')")
    @Log(title = "操作记录模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialOperate materialOperate)
    {
        return toAjax(materialOperateService.updateMaterialOperate(materialOperate));
    }

    /**
     * 删除操作记录模块
     */
    @PreAuthorize("@ss.hasPermi('material:operate:remove')")
    @Log(title = "操作记录模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{operateIds}")
    public AjaxResult remove(@PathVariable Long[] operateIds)
    {
        return toAjax(materialOperateService.deleteMaterialOperateByOperateIds(operateIds));
    }

    /**
     * 退货操作记录模块
     */
    @PostMapping("/output")
    public AjaxResult output(@RequestBody MaterialOperate materialOperate)
    {
        materialOperate.setOperateType(2);
        return toAjax(materialOperateService.outputMaterial(materialOperate));
    }
}
